import Vue from 'vue'
import Router, {RouterMount} from 'uni-simple-router';
import store from "@/store"
Vue.use(Router)
//初始化
const router = new Router({
    routes:[...ROUTES] //路由表
});
const whiteList = [] // no redirect whitelist

//全局路由前置守卫
router.beforeEach((to, from, next) => {
	let token =  store.state.hh_token
	
	let ignoreLogin = false
	if (to.meta&&to.meta.ignoreLogin) {  
		ignoreLogin = true
	}
	if(!ignoreLogin&&!token){
		if (whiteList.includes(to.name)) {
		      // 在免登录白名单，直接进入
		      next()
		}else{
			// 跳转到登录页面
			console.log("未登录跳转到登登录页面")
			next({ name: 'login'})
		}
	}else{
		next()
	}
})
// 全局路由后置守卫
router.afterEach((to, from) => {
})
export {
	RouterMount,
	router
}